﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.nm.db.Models.Terminal;
using com.nm.library.Excels;
using com.nm.library.Helper;

namespace TerminalAPI.ImportExcel
{
    [Export(typeof(ExcelImport))]
    public class ShopSKCExcel : ExcelImport
    {
        /// <summary>
        /// Excel字段映射
        /// </summary>
        private static Dictionary<string, ImportVerify> dictFields = new List<ImportVerify> {
            new ImportVerify{ ColumnName="年份",FieldName="Year",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="季节",FieldName="Season",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="店铺编号",FieldName="ShopCode",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="店铺名称",FieldName="ShopName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="陈列类别",FieldName="Category",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="零售区域",FieldName="OperationAreaName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="商品区域",FieldName="ParentAreaName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="最高陈列SKC",FieldName="ASKC",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="标准陈列SKC",FieldName="BSKC",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="最低陈列SKC",FieldName="CSKC",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="最高陈列容量",FieldName="ASKCCapacity",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="标准陈列容量",FieldName="BSKCCapacity",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
            new ImportVerify{ ColumnName="最低陈列容量",FieldName="CSKCCapacity",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,50,false,true)},
           }.ToDictionary(e => e.ColumnName, e => e);
        public override Dictionary<string, ImportVerify> DictFields => dictFields;
        public override ExcelImportType Type => ExcelImportType.SHOPSKCEXCEL;
        public override object SaveImportData(DataTable dt, Dictionary<string, object> extraInfo, int userId)
        {
            throw new NotImplementedException();
        }

        public override DataTable GetExportData(string Keys)
        {
            var dc = new TerminalEntities();
            string strSql = $"select * from report_skc_temp where 1=1 {Keys}";
            var result = dc.Database.SqlQuery<report_skc_temp>(strSql);
            // var query = (from shop in dc.report_skc_temp
            //             select shop).ToList();
            return DataTableHelper.LinqToDataTable(result);
        }
    }
}
